package guoan.service;

import guoan.core.dto.DataGridModel;
import guoan.core.dto.PageResponse;
import guoan.domain.CoachItem;
import guoan.repository.CoachItemRepository;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.google.common.base.Strings;
import com.google.common.collect.Maps;

@Service
@Transactional(readOnly = false)
public class CoachItemService extends PageSerivce<CoachItem> {
	protected final Logger log = LoggerFactory.getLogger(getClass());

	@Autowired
	private CoachItemRepository coachItemRepository;

	public PageResponse<CoachItem> page(DataGridModel dataGridModel, String key) {
		// TODO Auto-generated method stub
		String sql = "SELECT * FROM coach_item  ";
		if (!Strings.isNullOrEmpty(key)) {
			sql += " WHERE   contact_number_f like '%" + key + "%'";
			sql += " OR student_name like '%" + key + "%'";
			sql += " OR exam_time like '%" + key + "%'";
			sql += " OR train_name like '%" + key + "%'";
			if (key.equals("二")) {
				sql += " OR coach_type = 2";
			}
			if (key.equals("三")) {
				sql += " OR coach_type = 3";
			}
		}
		sql += " ORDER BY exam_time ASC";
		/*
		 * Page<CoachItem> page =
		 * coachItemRepository.findAll(buildSpecification(paramMap),
		 * buildPageRequest(dataGridModel));
		 */
		return queryPageByJpqlForEntity(sql, dataGridModel, CoachItem.class);
	}

	public void removeLast() {
		// TODO Auto-generated method stub
		coachItemRepository.removeLast();
	}
}
